package oj_kickstart;

import java.util.*;

public class CatchSome {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int T = sc.nextInt();
        for (int t = 0; t < T; t++) {
            int N = sc.nextInt();
            int K = sc.nextInt();
            int[] P = new int[N];
            int[] A = new int[N];
            Map<Integer, List<Integer>> position = new HashMap<>(); // 每种颜色的位置
            Map<Integer, Integer> curr = new HashMap<>(); // 每种颜色当前的头
            for (int i = 0; i < N; i++) {
                P[i] = sc.nextInt();
            }
            for (int i = 0; i < N; i++) {
                A[i] = sc.nextInt();
                if (!position.containsKey(A[i])) {
                    List<Integer> p = new ArrayList<>();
                    p.add(P[i]);
                    position.put(A[i], p);
                    curr.put(A[i], 0);
                } else {
                    position.get(A[i]).add(P[i]);
                }
            }
            for (Integer color : position.keySet()) {
                List<Integer> p = position.get(color);
                Collections.sort(p);
            }

            // 贪心，选取K个
            int count = 0;
            while (count < K) {
                // 选取增长最小的
                int minGrowth = Integer.MAX_VALUE;
                int minColor = -1;
                for (Integer color : position.keySet()) {
                    List<Integer> p = position.get(color);
                    Integer pi = curr.get(color);
                    if (pi == 0) {
                        if (p.get(pi) < minGrowth) {
                            minColor = color;
                            minGrowth = p.get(pi);
                        }
                    } else if (pi < p.size()){
                        if (p.get(pi) - p.get(pi - 1) < minGrowth) {
                            minColor = color;
                            minGrowth = p.get(pi) - p.get(pi - 1);
                        }
                    }
                }
                curr.put(minColor, curr.get(minColor) + 1);
                count++;
            }

            // 分别以每一个颜色作为最后的路，进行微调
            int min = Integer.MAX_VALUE;
            for (Integer c1 : position.keySet()) {
                int currMin = getCurrMin(position, curr, c1);
                // 以c1为主干之后，看是否可替换
                for (Integer c2 : position.keySet()) {

                }
                if (currMin < min) {
                    min = currMin;
                }
            }

            System.out.println(String.format("Case #%d: %d", t + 1, min));
        }
    }

    public static int getCurrMin(Map<Integer, List<Integer>> position, Map<Integer, Integer> curr, int color) {
        int currMin = 0;
        for (Integer c : position.keySet()) {
            if (c.equals(color) && curr.get(color) != 0) {
                currMin += position.get(c).get(curr.get(c) - 1);
            }
            if (!c.equals(color) && curr.get(color) != 0) {
                currMin += 2 * position.get(c).get(curr.get(c) - 1);
            }
        }
        return currMin;

    }
}
